/*
Copyright (c) 2025 HeZongLun
NahidaProject is licensed under Mulan PSL v2.
You can use this software according to the terms and conditions of the Mulan
PSL v2.
You may obtain a copy of Mulan PSL v2 at:
		 http://license.coscl.org.cn/MulanPSL2
THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY
KIND, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO
NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
See the Mulan PSL v2 for more details.
*/

#include "SortModule.h"

std::vector<int> NahidaProject::SortModule::BubbleSort(std::vector<int> vec) {
	int n = vec.size();
	std::vector<int> result = vec;

	for (int i = 0; i < n; ++i) {
		for (int j = 0; j < n - i - 1; ++j) {
			if (result[j] > result[j + 1]) {
				std::swap(result[j], result[j + 1]);
			}
		}
	}
	return result;
}

std::vector<int> NahidaProject::SortModule::SelectSort(std::vector<int> vec) {
	int n = vec.size();
	std::vector<int> result = vec;

	for (int i = 0; i < n - 1; ++i) {
		int index = i;
		for (int j = i; j < n; ++j) {
			if (result[j] < result[index]) {
				index = j;
			}
		}
		std::swap(result[index], result[i]);
	}

	return result;
}


std::vector<int> NahidaProject::SortModule::InsertSort(std::vector<int> vec) {
	int n = vec.size();
	std::vector<int> result = vec;

	for (int i = 1; i < n; ++i) {
		for (int j = i; j > 0; j--) {
			if (result[j] < result[j - 1]) {
				std::swap(result[j], result[j - 1]);
			}
			else {
				break;
			}
		}
	}

	return result;
}
